from easymoney.dao import main_force_control_dao, stock_distribution_dao
from easymoney.framework.mysql.core.db_factory import StockEntity


def save_stock_everyday():
    """
    更新每天最新的数据
    """
    for e in StockEntity.select():
        main_force_control_dao.fetch_latest_daily_data(e.stock_code)
        stock_distribution_dao.fetch_latest_daily_data(e.stock_code)


def save_stock_all():
    """
    保存股票的相关数据，股票代码从 stock 表中取，如果其它表已经存在则不会插入
    """

    for e in StockEntity.select():
        main_force_control_dao.fetch_all_data(e.stock_code)
        stock_distribution_dao.fetch_all_data(e.stock_code)


def query_all():
    return list(StockEntity.select().dicts())
